from django.shortcuts import render,redirect
from rest_framework.views import APIView
from rest_framework.response import Response
from django.core.paginator import Paginator
from .ser import *
from .models import *
# Create your views here.

class Login_API(APIView):
    def post(self,request):
        token = request.data.get('token')
        uid = request.data.get('uid')
        p = Party.objects.filter(token=token,uid=uid).first()
        if p:
            return Response({"code":200,'mes':'登录成功'})
        else:
            return Response({"code":10010,'mes':'请前往页面进行授权'})

class Party_API(APIView):
    def post(self, request):
        token = request.data.get('token')
        uid = request.data.get('uid')
        mobile = request.data.get('mobile')
        #添加用户表
        Juser.objects.create(username=mobile).save()
        #添加三方登录表
        j = Juser.objects.filter(username=mobile).first()
        Party.objects.create(name='微博',uid=uid,token=token,user_id=j.id).save()
        return Response({"code":200,'mes':'授权成功','userid':uid})








